// var link="http://api.yikch.com";
// var link="http://192.168.0.110:8088";
var link="http://192.168.1.5:8088";
var isToken = '';
var isCheckInfo = '';
var token=GetCookie('token');
var mobile='';
if(GetCookie('mobile')){
	mobile = GetCookie('mobile');
}else{
	mobile = '';
}
var public = {
	init:function(){
		this.layuiUse();
		this.goDetail();	
		this.goHistory();
		this.goPerson();
		this.goAddress();
		this.goIndex();
		this.goOrderList();
		this.goPersonInfo();
		this.goFindpwd();
		this.goProfit();
		this.goStrategy();
		this.goCashoutList();
		this.goMyCode();
		this.goPay();
		// this.goTop();
	},
	layuiUse:function(){
		layui.use(['form'], function(){
		  	var form = layui.form;
		});
	},
	// 倒计时
	countDown:function(){
		function tow(n) {
		    return n >= 0 && n < 10 ? '0' + n : '' + n;
		}
  		function getDate() {
		    var oDate = new Date();//获取日期对象
		    var oldTime = oDate.getTime();//现在距离1970年的毫秒数
			var newDate=new Date();
			var min=newDate.getMinutes();
			newDate.setMinutes(min+5);



		    var newTime = newDate.getTime();//2019年距离1970年的毫秒数
		    var second = Math.floor((newTime - oldTime) / 1000);//未来时间距离现在的秒数
		    var day = Math.floor(second / 86400);//整数部分代表的是天；一天有24*60*60=86400秒 ；
		    second = second % 86400;//余数代表剩下的秒数；
		    var hour = Math.floor(second / 3600);//整数部分代表小时；
		    second %= 3600; //余数代表 剩下的秒数；
		    var minute = Math.floor(second / 60);
		    second %= 60;
		    var str = //tow(day) + '<span class="time">天</span>'
		        //+ tow(hour) + '<span class="time">小时</span>'
		        + tow(minute) + '<span class="time">分钟</span>'
		        + tow(second) + '<span class="time">秒</span>';
		    $('span[name="countDownDom"]').html(str);
	  	}
	  	getDate();
	  	setInterval(getDate, 1000);

	},
	//判断token是否失效
	isToken:function(){
		$.ajax({
            type: 'post',
            url:link+'/mobile/loginStatus',
            data:{
                'token':token
			},
			async:false,
			dataType: 'json',
            success: function (res) {
				isToken = res.code;
            },
            error:function(res){
                layer.msg(res.message);
            },
		});
		return isToken;
	},
	goHistory:function(){
		$('body').on('click','.goHistory',function(){
			// if(document.referrer.indexOf('login')!=-1){
			// 	window.location.href="../../index.html";
			// }else if(document.referrer.indexOf('findPassword')!=-1||document.referrer.indexOf('address')!=-1||document.referrer.indexOf('records')!=-1){
			// 	window.location.href="../../index.html";
			// }else{
				window.history.go(-1);
			// }
		})
	},
	//跳转个人中心
	goPerson:function(){
		let isTokenNow = public.isToken();
		$('body').on('click','.goPerson',function(){	
			if(isTokenNow!=10000){
                layer.msg('<p class="colorSystem font16 alignC mt15">请您先登录~</p>',{time:600},function(){
                    window.location.href="../../html/login/login.html";
                });
            }else{
				window.location.href="../../html/person/person.html";
            }
		});
	},
	//返回顶部
	goTop:function(){
		$('.goTop').on('click',function(){
			$('body,html').animate({
				scrollTop: 0
			},100);
		})
	},
	//跳转首页
	goIndex:function(){
		$('body').on('click','.goIndex',function(){
			window.location.href="/index.html";
		});
	},
	//跳转详情页
	goDetail:function(){
		$('body').on('click','.goDetail',function(){
			window.location.href="../html/detail/detail.html?proId="+$(this).attr('name');
		});
	},
	//跳转收货地址
	goAddress:function() {
		$('body').on('click','.goAddress',function(){
			window.location.href="../address/addressList.html";
		});
	},
	//跳转我的订单
    goOrderList:function(){
        $('body').on('click','.goOrderList',function(){
			window.location.href="/html/person/orderList.html";
		});
	},
	//跳转我的邀请码
	goMyCode:function(){
		$('body').on('click','.goMyCode',function(){
			window.location.href="/html/person/myCode.html";
		});
	},
	//跳转修改个人信息
	goPersonInfo:function(){
		$('body').on('click','.goPersonInfo',function(){
			window.location.href="/html/person/personInfo.html";
		});
	},
	//跳转找回密码
	goFindpwd:function(){
		$('body').on('click','.goFindpwd',function(){
			window.location.href="/html/login/findPassword.html";
		});
	},
	//跳转收益
	goProfit:function(){
		let isTokenNow = public.isToken();
		$('body').on('click','.goProfit',function(){	
			if(isTokenNow!=10000){
                layer.msg('<p class="colorSystem font16 alignC mt15">请您先登录~</p>',{time:600},function(){
                    window.location.href="../../html/login/login.html";
                });
            }else{
				window.location.href="../../html/profit/profit.html";
            }
		});
	},
	//跳转我的提现列表
	goCashoutList:function(){
		$('body').on('click','.goCashoutList',function(){	
			window.location.href="../../html/person/cashOutList.html";
		});
	},
	//跳转产品攻略
	goStrategy:function(){
		$('body').on('click','.goStrategy',function(){
			window.location.href="/html/strateg/strateg.html";
		});
	},
	//去支付
	goPay:function(){
		$('body').on('click','.goPay',function(){
			console.log('去支付');
			// window.location.href="/html/strateg/strateg.html";
		});
	},
	//数字以逗号分隔
	numSplit1:function(n){
		var b = parseInt(n).toString();
		var len = b.length;
		if (len <= 3) { return b; }
		var r = len % 3;
		return r > 0 ? b.slice(0, r) + "," + b.slice(r, len).match(/\d{3}/g).join(",") : b.slice(r, len).match(/\d{3}/g).join(",");
	},
	//数字以逗号分隔带小数点
	/**
	 * 格式化金额
	 * v     [要转换的数字]
	 * len   [小数点位数,默认2位]
	 * split [分隔符,默认',']
	 * return {[type]}       [返回转换完的字符串]
	 */
	numSplit2:function(v,len,split){
		split=split||",",len=Math.abs((+len)%20||2);
			v = parseFloat((v + "").replace(/[^\d\.-]/g, "")).toFixed(len) + ""; 
					return v.replace(/\d+/,function(v){
						var lit = v.length%3==0;
						var index = lit?v.length-3:-1;
						return v.split('').reverse().join('').replace(/\d{3}/g, function(k,l) {
						return k + ((l==index&&lit)?"":split);
					}).split('').reverse().join('')
				}
			);
	}
};
public.init();

          